//
//  YQGoodsScenicspotOrderDetailsCell.swift
//  MuYing
//
//  Created by tbb on 2020/3/11.
//  Copyright © 2020 TBB. All rights reserved.
//

import UIKit

@objc protocol YQGoodsScenicspotOrderDetailsCellDelegate:NSObjectProtocol {

    func selectSceneGoodItemModel(_ model:YQGoodsOrderItemModel)
    
    func selectSceneCancelGoodItemModel(_ detailModel:YQGoodsOrderItemModel)

}

class YQGoodsScenicspotOrderDetailsCell: YQTableViewBaseCell {

    @IBOutlet weak var goodIcon: UIImageView!
    @objc var refundModel = YQGoodsOrderDetailsModel()
    
    @objc var orderModel = YQGoodsOrderModel()

    @objc var itemModel = YQGoodsOrderItemModel()

    @objc weak var delegate:YQGoodsScenicspotOrderDetailsCellDelegate?

    @IBOutlet weak var resetBtn: QMUIGhostButton!
    @IBOutlet weak var refundBtn: QMUIGhostButton!
    @IBOutlet weak var titleLb: UILabel!
    
    @IBOutlet weak var numLb: UILabel!
    @IBOutlet weak var priceLb: UILabel!
    @IBOutlet weak var specificationLb: UILabel!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        self.refundBtn.layer.borderColor = appThemeColor.cgColor
        
        self.refundBtn.setTitleColor(appThemeColor, for: .normal)
        
        self.resetBtn.layer.borderColor = UIColor.darkText.cgColor
        
        self.resetBtn.setTitleColor(UIColor.darkText, for: .normal)
        
        self.refundBtn.addTarget(self, action: #selector(clickRefundAction(_:)), for: .touchUpInside)

    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    
    @objc func setRefundSceneDetailModel(_ orderStatus:String, _ refundStatus:String){
        //订单详情页里单个商品的售后交互

        if orderStatus == "201" && refundStatus == "0" {
            self.refundBtn.setTitle(kYQLSSwift("退款"), for: .normal)
            self.refundBtn.isUserInteractionEnabled = true
            self.resetBtn.isHidden = true

        }
        
        if orderStatus == "201" && refundStatus == "7" {//用户撤销
            self.refundBtn.setTitle(kYQLSSwift("退款"), for: .normal)
            self.refundBtn.isUserInteractionEnabled = true
            self.resetBtn.isHidden = true

        }
        
        if refundStatus == "5" {//用户撤销
            self.refundBtn.setTitle(kYQLSSwift("退货"), for: .normal)
            self.refundBtn.isUserInteractionEnabled = true
            self.resetBtn.isHidden = true

        }
        
        if refundStatus == "0" {
            if orderStatus == "301" || orderStatus == "302" || orderStatus == "303"  {
                self.refundBtn.setTitle(kYQLSSwift("退货"), for: .normal)
                self.refundBtn.isUserInteractionEnabled = true
                self.resetBtn.isHidden = true

            }
        }
        
        if refundStatus == "7" {
            if orderStatus == "301" || orderStatus == "302" || orderStatus == "303"  {
                self.refundBtn.setTitle(kYQLSSwift("退货"), for: .normal)
                self.refundBtn.isUserInteractionEnabled = true
                self.resetBtn.isHidden = true

            }
        }
        
        if refundStatus == "1" || refundStatus == "2" {
            self.refundBtn.setTitle(kYQLSSwift("退款中"), for: .normal)
            self.refundBtn.isUserInteractionEnabled = false
            self.resetBtn.isHidden = false
            self.resetBtn.setTitle(kYQLSSwift("撤销申请"), for: .normal)
            self.resetBtn.layer.borderColor = UIColor.darkGray.cgColor
            self.resetBtn.setTitleColor(UIColor.darkGray, for: .normal)
            self.resetBtn.addTarget(self, action: #selector(clickCancelRefundAction(_:)), for: .touchUpInside)
            self.resetBtn.isHidden = false

        }
        
        if refundStatus == "4"{
            self.refundBtn.setTitle(kYQLSSwift("填写物流"), for: .normal)
            self.refundBtn.isUserInteractionEnabled = true
            self.resetBtn.isHidden = false
            self.resetBtn.setTitle(kYQLSSwift("撤销申请"), for: .normal)
            self.resetBtn.layer.borderColor = UIColor.darkGray.cgColor
            self.resetBtn.setTitleColor(UIColor.darkGray, for: .normal)
            self.resetBtn.addTarget(self, action: #selector(clickCancelRefundAction(_:)), for: .touchUpInside)
            self.resetBtn.isHidden = false

        }
        
        if refundStatus == "-1" {
            self.refundBtn.isHidden = true
        }else{
            self.refundBtn.isHidden = false

        }
    }
    
    //撤销申请
    @objc func clickCancelRefundAction(_ button:QMUIGhostButton)
    {
        self.delegate?.selectSceneCancelGoodItemModel(self.itemModel)

    }
    
    @objc func clickRefundAction(_ button:QMUIGhostButton)
    {
        self.delegate?.selectSceneGoodItemModel(self.itemModel)

    }
    
    
    @objc func setRefundSceneMoreModel(_ refundModel:YQGoodsOrderDetailsModel, _ indexPath:NSIndexPath){
        
        self.refundModel = refundModel

        if refundModel.orderItemList.count != 0 {
            self.itemModel = refundModel.orderItemList[indexPath.row]

        }

    }
    
    @objc func setRefundOrderItemModel(_ orderModel:YQGoodsOrderModel, _ indexPath:NSIndexPath){
        
        self.orderModel = orderModel

        if orderModel.orderItemList.count != 0 {
            self.itemModel = orderModel.orderItemList[indexPath.row]

        }

    }
}
